Get the frequency of the elementsΒΆ
Get the frequency of the elements in a list.
import collections
L = [10, 10, 10, 10, 20, 20, 20, 20, 40, 40, 50, 50, 30]
print("Original List : ", L)
ctr = collections.Counter(L)
print("Frequency of the elements in the List : ", ctr)
Output:
Frequency of the elements in the List: \
Counter({10: 4, 20: 4, 40: 2, 50: 2, 30: 1})